package com.yaya.generator.config;

import com.baomidou.mybatisplus.generator.config.DataSourceConfig.Builder;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * 数据源配置
 */
@Configuration
public class DataSourceConfig {

    /** 数据库连接 */
    public static String URL;

    /** 数据库账号 */
    public static String USERNAME;

    /** 数据库密码 */
    public static String PASSWORD;

    public static Builder builder(){
        return new Builder(URL, USERNAME,PASSWORD)
                .dbQuery(new MySqlQuery())
                //Java类型和数据库类型转换
                .typeConvert(new MySqlTypeConvert())
                //处理 SQL 语句中的关键字
                .keyWordsHandler(new MySqlKeyWordsHandler());

    }


    @Value("${spring.datasource.url}")
    public static void setURL(String URL) {
        DataSourceConfig.URL = URL;
    }

    @Value("${spring.datasource.username}")
    public static void setUSERNAME(String USERNAME) {
        DataSourceConfig.USERNAME = USERNAME;
    }

    @Value("${spring.datasource.password}")
    public static void setPASSWORD(String PASSWORD) {
        DataSourceConfig.PASSWORD = PASSWORD;
    }
}
